import { App } from 'vue'
import { ElMessageBox } from 'element-plus'
import { ElMessage } from 'element-plus/es'
import { Assist, AssistErrorType } from '@lhy-assist/utils'

export default {
  install(app: App) {
    Assist.extendOptions({
      resolveError: e => {
        if (e.message) {
          switch (e.type) {
            case AssistErrorType.info:
              ElMessage.info(e.message)
              break
            case AssistErrorType.warning:
              ElMessage.warning(e.message)
              break
            default:
              ElMessage.error(e.message)
          }
        }
        throw e
      },
      confirm: (title, content) =>
        new Promise<void>((resolve, reject) => ElMessageBox.confirm(content, title).then(() => resolve(), reject)),
      message: ElMessage,
    })
  },
}
